import request from "../utils/repuest";

type AxiosRequestConfig<T> = {
    data: {
        code: string
        message: string
        data: T
    }
}

// type lbt = {
//     alt: string
//     link: string
//     img: string
//     bannerid: string
//     flag: boolean
// }


// 轮播图数据获取
export function lbtData() {
    return request.get<any, AxiosRequestConfig<string>>('/banner/list')
}




// 发送短信验证码
export function getUniteLoginUrl(params: string) {
    return request.post<any, AxiosRequestConfig<number>>('/user/dosendmsgcode', params)
}

// 注册
type zhuce = {
    tel: string
    // telcode?: string
    password: string
}
export function zhuCe(params: zhuce) {
    return request.post('/user/dofinishregister', params)
}

// 用户已被注册
export function userZhuCe(params: string) {
    return request.post('/user/docheckphone', params)
}


// 验证码是否正确
// export function zhuCe(params: zhuce) {
//     return request.post<any, AxiosRequestConfig<string>>('/user/docheckcode', params)
// }







// 获取商品列表
type datalist = {
    banners: []
    brand: string
    category: string
    desc: string
    discount: number
    img1: string
    proname: string
}
export function shangPin(count: number, limitNum: number) {
    return request.get<any, AxiosRequestConfig<datalist[]>>('/pro/list', {
        params:
        {
            count,
            limitNum
        }
    })
}


//获取商品详情数据

type xq = {
    img1: string
    img2: string
    img3: string
    img4: string
}


export function shangPinXiangQing(body: string) {
    return request.get<any, AxiosRequestConfig<xq>>(`/pro/detail/${body}`)
}



// 获取秒杀列表
export function shangPinMiaoSha(count: number, limitNum: number) {
    return request.get<any, AxiosRequestConfig<datalist[]>>('/pro/seckilllist', {
        params:
        {
            count,
            limitNum
        }
    })
}




// 登录
type denglu = {
    loginname: string
    password: string
}
type datadenglu = {
    token: string
    userid: string
}
export function dengLu(params: denglu) {
    return request.post('/user/login', params)
}




// 获取购物车

export function gouwuche(params: string) {
    return request.post<any>('/cart/list', { userid: params })
}



// 加入购物车

type addGou = {
    userid: string
    proid: string
    num: string
}

export function Addgouwuche(params: addGou) {
    return request.post('/cart/add', params)
}


// 更新商品数量

type upGou = {
    cartid: string
    num: number
}

export function upgouwuche(params: upGou) {
    return request.post('/cart/updatenum', params)
}



// 查看数据选中状态

type check = {
    cartid: string
    flag: boolean
}

export function checked(params: check) {
    return request.post('/cart/selectone', params)
}


// 查看全部数据选中状态

type allcheck = {
    userid: string
    type: boolean
}

export function allchecked(params: allcheck) {
    return request.post('/cart/selectall', params)
}


// 删除单条数据



export function removechecked(params: string) {
    return request.post('/cart/remove', { cartid: params })
}


// 城市列表


// export function citylist() {
//     return requestCity.get('/city.json')
// }